package com.iqiyi.pps.epg.core.model.program;

/**
 * Created by karkarrotxu on 2015/8/17.
 */
public class ProgramCheckData {
    public static final long REMIND_TIME1 = 86400000L;
    public static final long REMIND_TIME2 = 7200000L;
//    public static final long REMIND_TIME1 = 3600000L;
//    public static final long REMIND_TIME2 = 2700000L;
    public static final long CHECK_BEFORE_TIME1 = 1800000L;
    public static final long CHECK_BEFORE_TIME2 = 300000L;

    public static final long CHECK_AFTER_TIME = 600000L;
    public enum STATUS {
        PHASE_REMIND_TIME1, PHASE_REMIND_TIME2, PHASE_CHECK_FIRST, IN_WAIT, PHASE_CHECK_SECOND, PHASE_OVER_CHECK
    }

    private boolean readyToRemove = false;

    private long id;
    private long fatherId;
    private long startTime;
    private long remindTime1;
    private long remindTime2;
    private long recordTime1;
    private long recordTime2;
    private long overCheckTime;
    private long lastExcuteTime;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public long getFatherId() {
        return fatherId;
    }

    public void setFatherId(long fatherId) {
        this.fatherId = fatherId;
    }

    public long getStartTime() {
        return startTime;
    }

    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }

    public void initByStartTime(long startTime) {
        this.remindTime1 = startTime - REMIND_TIME1;
        this.remindTime2 = startTime - REMIND_TIME2;
        this.recordTime1 = startTime - CHECK_BEFORE_TIME1;
        this.recordTime2 = startTime - CHECK_BEFORE_TIME2;
        this.startTime = startTime;
        this.overCheckTime = startTime + CHECK_AFTER_TIME;
        this.lastExcuteTime = System.currentTimeMillis();
    }

    public STATUS getCheckStatus(long checkTime) {
        if (checkTime >= overCheckTime) {
            return STATUS.PHASE_OVER_CHECK;
        } else if (checkTime >= recordTime2) {
            return lastExcuteTime > recordTime2 ? STATUS.IN_WAIT : STATUS.PHASE_CHECK_SECOND;
        } else if (checkTime >= recordTime1) {
            return lastExcuteTime > recordTime1 ? STATUS.IN_WAIT : STATUS.PHASE_CHECK_FIRST;
        } else if (checkTime >= remindTime2) {
            return lastExcuteTime > remindTime2 ? STATUS.IN_WAIT : STATUS.PHASE_REMIND_TIME2;
        } else if (checkTime >= remindTime1) {
            return lastExcuteTime > remindTime1 ? STATUS.IN_WAIT : STATUS.PHASE_REMIND_TIME1;
        } else {
            return STATUS.IN_WAIT;
        }
    }

    public void setLastExcuteTime(long excuteTime) {
        this.lastExcuteTime = excuteTime;
    }

    public boolean isReadyToRemove() {
        return readyToRemove;
    }

    public void setReadyToRemove(boolean readyToRemove) {
        this.readyToRemove = readyToRemove;
    }
}
